<div id="register" class="login_wrapper">
    <div class="animate form login_form">
        <section class="login_content">
            <form action="javaScript:void(0)">
                <h1>管理系统注册</h1>
                <div>
                    <input type="text"
                           v-model="user.userName"
                           class="form-control"
                           placeholder="Username"
                           required=""/>
                </div>
                <div>
                    <input type="text"
                           v-model="user.email"
                           class="form-control"
                           placeholder="User Email"
                           required="">
                </div>
                <div>
                    <input type="password"
                           v-model="user.password"
                           class="form-control"
                           placeholder="Password"
                           required=""/>
                </div>
                <div>
                    <a @click="register()"
                       class="btn btn-default submit"
                       href="javascript:void(0)" style="width: 45%;float: left">register</a>
                    <a href="/login" class="to_register btn btn-default submit" style="width: 45%;"> Log in </a>
                </div>
                <div class="clearfix"></div>

                <div class="separator">
                    <div class="clearfix"></div>
                    <br/>
                    <div>
                        <h1><i class="fa fa-paw"></i> Java_Spring_Boot</h1>
                        <p>©2022 All Rights Reserved. Java_Spring_Boot! is a Bootstrap 3 template. Privacy and Terms</p>
                    </div>
                </div>
            </form>
        </section>
    </div>
</div>
<script>
    var registerVue = new Vue({
        el: "#register",
        data: {
            user: {
                userName: "",
                email: "",
                password: "",
            },
        },
        methods: {
            register: function () {
                if (this.user.userName == "" || this.user.password == "" || this.user.email == "") {
                    alert("Please input user name or password or email.");
                    return;
                }

                var self = this;
                $.ajax({
                    url: "/api/user",
                    type: "post",
                    contentType: "application/json",
                    data: JSON.stringify(self.user),
                    success: function (rs) {
                        if (rs.status == 200) {
                            window.location.href = "/common/dashboard";
                        } else {
                            layer.msg(rs.message, { icon: 0 });
                        }
                    },
                    error: function (data) {
                        layer.alert(data.responseText, { icon: 0 });
                    },
                });
            },
        },
    });
</script>